package com.xyzh05.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xyzh05.dao.MaterialDao;
import com.xyzh05.model.Material;
import com.xyzh05.service.MaterialManager;
import com.xyzh05.util.PageBean;

@Service("materialManager")
@WebService(serviceName = "MaterialService", endpointInterface = "com.xyzh05.service.MaterialManager")
public class MaterialManagerImpl extends GenericManagerImpl<Material, Long> implements MaterialManager {
    MaterialDao materialDao;

    @Autowired
    public MaterialManagerImpl(MaterialDao materialDao) {
        super(materialDao);
        this.materialDao = materialDao;
    }

	public PageBean findList(PageBean pageBean, Material material) {
		StringBuilder sb = new StringBuilder();
		List list = new ArrayList();
		sb.append("  from Material where 1 = 1 ");

		if (pageBean != null) {
			if (pageBean.getSortCriterion() != null) {
				sb.append(" order by ");
				sb.append(pageBean.getSortCriterion() + " ");
				if (pageBean.getSortParamDirection() != null) {
					sb.append(pageBean.getSortParamDirection());
				}
			}
		}
		return materialDao.getPageByHQL(sb.toString(), pageBean, list.toArray());
	}
	
	public List<Material> doSelSchool(Long vipServiceId){
		String hql = " select new Material(m.id, m.school) from Material m where m.vipService.id = ? ";
		return (List<Material>) materialDao.findQuery(hql, vipServiceId);
	}
}